﻿using Avalonia.Controls;
using Avalonia.ReactiveUI;
using AvalSqlIndexManager.Models;
using AvalSqlIndexManager.ViewModels;
using DynamicData;
using ReactiveUI;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace AvalSqlIndexManager.Views;

public partial class MainWindow : ReactiveWindow<MainViewModel>
{
    
    public MainWindow()
    {
        InitializeComponent();
        this.WhenActivated(action =>
             action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync)));
    }

    private async Task DoShowDialogAsync(InteractionContext<IndexEditViewModel,
                                        TableIndex?> interaction)
    {
        var dialog = new IndexEditWindow();
        dialog.DataContext = interaction.Input;

        var result = await dialog.ShowDialog<TableIndex?>(this);
        interaction.SetOutput(result);
    }
}
